package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:varchar(11);unique;comment:'用户手机号'"`
	Password string `gorm:"type:char(32);comment:'密码'"`
}

func (u *User) GetUserByMobile() error {
	return DB.Where("mobile=?", u.Mobile).Limit(1).Find(&u).Error
}

func (u *User) Register() error {
	return DB.Create(&u).Error
}

func (u *User) UpdatePwd() error {
	return DB.Updates(&u).Error
}

type RealNameUser struct {
	gorm.Model
	UserId   int64
	RealName string
	IdCard   string
}

func (r *RealNameUser) GetRealNameByUserId() error {
	return DB.Where("user_id=?", r.UserId).Limit(1).Find(&r).Error
}

func (r *RealNameUser) GetUserByIdCard() error {
	return DB.Where("id_card=?", r.IdCard).Limit(1).Find(&r).Error
}

func (r *RealNameUser) GetRealNameByIdCard() error {
	return DB.Where("id_card=?", r.IdCard).Limit(1).Find(&r).Error
}

func (r *RealNameUser) CreateRealName() error {
	return DB.Create(&r).Error
}

func (u *User) GetUserById() error {
	return DB.Where("id=?", u.ID).Limit(1).Find(&u).Error
}
